<?php
require_once 'command/Command.php';
require_once 'database/Tag.php';
require_once 'database/DatabaseConnection.php';

class GetTagsCommand implements Command{
	
	private $tag;
	private $ids;
	
	public function __construct($ids = 0){
		if($ids != 0){
			$this->ids = $this->toArray($ids);
			$this->tag = new Tag();
		}
	}
	
	public function execute(){
		$string = "<tags>";
		DatabaseConnection::connect();
		$it = $this->tag->getTags($this->ids)->getIterator();
		DatabaseConnection::disconnect();
		while($it->valid()){
			$arr = $it->current();
			$string .= "<tag>";
			$string .= 	"<id>".$arr['id']."</id>";
			$string .=	"<name>".$arr['name']."</name>";
			$string .= "</tag>";
			$it->next();
		}
		$string .= "</tags>";
		return $string;
	}
	
	public function toArray($ids){
		return split(";", $ids);
	}
	
	public function getIds(){
		return $this->getIds();
	}
}